package io;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.time.LocalDateTime;
import java.util.Arrays;

public class Demo06 {
    public static void main(String[] args) throws IOException {
        // 不优雅
//        FileInputStream fileInputStream = null;
//        try {
//            fileInputStream = new FileInputStream("d:/DianChi.html");
//
//            Long start = System.currentTimeMillis();
//            int n;
//            byte[] bytes = new byte[1024];
//            while ((n = fileInputStream.read(bytes)) != -1) {
////            System.out.println(Arrays.toString(bytes));
//            }
//            System.out.println("Time: " + (System.currentTimeMillis() - start));
//        } finally {
//            fileInputStream.close();
//        }

        // 优雅地编写 注意括号里的对象需要实现 Closeable
        try (FileInputStream fileInputStream = new FileInputStream("d:/DianChi.html")) {


            Long start = System.currentTimeMillis();
            int n;
            byte[] bytes = new byte[1024];
            while ((n = fileInputStream.read(bytes)) != -1) {
//            System.out.println(Arrays.toString(bytes));
            }
            System.out.println("Time: " + (System.currentTimeMillis() - start));
        }
    }
}
